﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;

namespace points.Model
{
    public class CustomerPointsConversion : Customer
    {
        /*
        public int Merchant_Pk { get; set; }
        public DateTime Merchant_Add_Dt { get; set; }
        public DateTime Merchant_Mod_Dt { get; set; }
        public string Merchant_Obj_Name { get; set; }
        public string Merchant_Marked_Delete_Y_N { get; set; }
        public int Merchant_Rec_Id { get; set; }
        public string Merchant_Descr { get; set; }

        public int ValPoint { get; set; }
        public int ValDollar { get; set; }

        public CustomerPointsConversion
        (
            int pk,
            DateTime addDt,
            DateTime modDt,
            string markedDeleteYN,
            int recId,
            int fkLocale,
            int fkCustomerTypeId,
            int fkCustomerStatusTypeId,
            string userId,
            string password,
            string salutation,
            string nameFirst,
            string nameMiddle,
            string nameLast,
            string email,
            string website,
            string descr,
            int valPoint,
            int valDollar
        )
            : base
                (
               pk,
               addDt,
               modDt,
               markedDeleteYN,
               recId,
               fkLocale,
               fkCustomerTypeId,
               fkCustomerStatusTypeId,
               userId,
               password,
               salutation,
               nameFirst,
               nameMiddle,
               nameLast,
               email,
               website,
               descr
                )
        {
            Init
            (
                pk,
                addDt,
                modDt,
                markedDeleteYN,
                recId,
                valPoint,
                valDollar
            );
        }

        public void Init
        (
            int pk,
            DateTime addDt,
            DateTime modDt,
            string markedDeleteYN,
            int recId,
            int valPoint,
            int valDollar
        )
        {
            Merchant_Pk = pk;
            Merchant_Add_Dt = addDt;
            Merchant_Mod_Dt = modDt;
            Merchant_Obj_Name = ConfigurationManager.AppSettings["OBJECT_CUSTOMER_POINTS_CONVERSION"];
            Merchant_Marked_Delete_Y_N = markedDeleteYN;
            Merchant_Rec_Id = recId;
            Merchant_Descr = "";

            ValPoint = valPoint;
            ValDollar = valDollar;
        }



        new public int Insert(bool transactionShared)
        {
            int rowsAffected = 0;

            string strConn = (string)ConfigurationManager.ConnectionStrings["POINTS_PROD"].ToString();

            using (SqlConnection conn = new SqlConnection(strConn))
            {
                conn.Open();

                //SqlParameter paramPk = new SqlParameter("@param1", SqlDbType.NVarChar);
                SqlParameter paramAddDt = new SqlParameter("@paramAddDt", SqlDbType.DateTime2);
                SqlParameter paramModDt = new SqlParameter("@paramModDt", SqlDbType.DateTime2);
                SqlParameter paramObjName = new SqlParameter("@paramObjName", SqlDbType.NVarChar);
                SqlParameter paramMarkedDeleteYN = new SqlParameter("@paramMarkedDeleteYN", SqlDbType.NVarChar);
                SqlParameter paramRecId = new SqlParameter("@paramRecId", SqlDbType.Int);
                SqlParameter paramFkLocale = new SqlParameter("@paramFkLocale", SqlDbType.Int);
                SqlParameter paramFkCustomerTypeId = new SqlParameter("@paramFkCustomerTypeId", SqlDbType.Int);
                SqlParameter paramFkCustomerStatusTypeId = new SqlParameter("@paramFkCustomerStatusTypeId", SqlDbType.Int);
                SqlParameter paramUserId = new SqlParameter("@paramUserId", SqlDbType.NVarChar);
                SqlParameter paramPassword = new SqlParameter("@paramPassword", SqlDbType.NVarChar);
                SqlParameter paramSalutation = new SqlParameter("@paramSalutation", SqlDbType.NVarChar);
                SqlParameter paramNameFirst = new SqlParameter("@paramNameFirst", SqlDbType.NVarChar);
                SqlParameter paramNameFirstCanon = new SqlParameter("@paramNameFirstCanon", SqlDbType.NVarChar);
                SqlParameter paramNameMiddle = new SqlParameter("@paramNameMiddle", SqlDbType.NVarChar);
                SqlParameter paramNameMiddleCanon = new SqlParameter("@paramNameMiddleCanon", SqlDbType.NVarChar);
                SqlParameter paramNameLast = new SqlParameter("@paramNameLast", SqlDbType.NVarChar);
                SqlParameter paramNameLastCanon = new SqlParameter("@paramNameLastCanon", SqlDbType.NVarChar);
                SqlParameter paramEmail = new SqlParameter("@paramEmail", SqlDbType.NVarChar);
                SqlParameter paramWebsite = new SqlParameter("@paramWebsite", SqlDbType.NVarChar);
                SqlParameter paramDescr = new SqlParameter("@paramDescr", SqlDbType.NVarChar);


                paramAddDt.Value = this.Add_Dt;
                paramModDt.Value = this.Mod_Dt;
                paramObjName.Value = this.Obj_Name;
                paramMarkedDeleteYN.Value = this.Marked_Delete_Y_N;
                paramRecId.Value = this.Rec_Id;
                paramFkLocale.Value = this.Fk_Locale;
                paramFkCustomerTypeId.Value = this.Fk_Customer_Type_Id;
                paramFkCustomerStatusTypeId.Value = this.Fk_Customer_Status_Type_Id;
                paramUserId.Value = this.Userid;
                paramPassword.Value = this.Password;
                paramSalutation.Value = this.Salutation;
                paramNameFirst.Value = this.Name_First;
                paramNameFirstCanon.Value = this.Name_First_Canon;
                paramNameMiddle.Value = this.Name_Middle;
                paramNameMiddleCanon.Value = this.Name_Middle_Canon;
                paramNameLast.Value = this.Name_Last;
                paramNameLastCanon.Value = this.Name_Last_Canon;
                paramEmail.Value = this.Email;
                paramWebsite.Value = this.Web;
                paramDescr.Value = this.Descr;

                using (SqlCommand cmd = conn.CreateCommand())
                {
                    string sqlString =
                   " INSERT INTO CUSTOMER" +
                   " (" +
                        //" pk," +
                    " obj_name," +
                    " add_dt," +
                    " mod_dt," +
                    " marked_delete_y_n," +
                    " rec_id," +
                    " fk_locale," +
                    " fk_customer_type_id," +
                    " fk_customer_status_type_id," +
                    " userid," +
                    " password," +
                    " salutation," +
                    " name_first," +
                    " name_first_canon," +
                    " name_middle," +
                    " name_middle_canon," +
                    " name_last," +
                    " name_last_canon," +
                    " email," +
                    " web," +
                    " descr" +
                   " )" +
                   " VALUES" +
                   " (" +
                       " @paramObjName," +
                       " @paramAddDt," +
                       " @paramModDt," +
                       " @paramMarkedDeleteYN," +
                       " @paramRecId," +
                       " @paramFkLocale," +
                       " @paramFkCustomerTypeId," +
                       " @paramFkCustomerStatusTypeId," +
                       " @paramUserId," +
                       " @paramPassword," +
                       " @paramSalutation," +
                       " @paramNameFirst," +
                       " @paramNameFirstCanon," +
                       " @paramNameMiddle," +
                       " @paramNameMiddleCanon," +
                       " @paramNameLast," +
                       " @paramNameLastCanon," +
                       " @paramEmail," +
                       " @paramWebsite," +
                       " @paramDescr" +
                   " )";

                    cmd.CommandText = sqlString;

                    cmd.Parameters.Add(paramAddDt);
                    cmd.Parameters.Add(paramModDt);
                    cmd.Parameters.Add(paramObjName);
                    cmd.Parameters.Add(paramMarkedDeleteYN);
                    cmd.Parameters.Add(paramRecId);
                    cmd.Parameters.Add(paramFkLocale);
                    cmd.Parameters.Add(paramFkCustomerTypeId);
                    cmd.Parameters.Add(paramFkCustomerStatusTypeId);
                    cmd.Parameters.Add(paramUserId);
                    cmd.Parameters.Add(paramPassword);
                    cmd.Parameters.Add(paramSalutation);
                    cmd.Parameters.Add(paramNameFirst);
                    cmd.Parameters.Add(paramNameFirstCanon);
                    cmd.Parameters.Add(paramNameMiddle);
                    cmd.Parameters.Add(paramNameMiddleCanon);
                    cmd.Parameters.Add(paramNameLast);
                    cmd.Parameters.Add(paramNameLastCanon);
                    cmd.Parameters.Add(paramEmail);
                    cmd.Parameters.Add(paramWebsite);
                    cmd.Parameters.Add(paramDescr);

                    SqlTransaction transaction = null;
                    try
                    {
                        //conn.Open();
                        transaction = conn.BeginTransaction();
                        cmd.Transaction = transaction;
                        rowsAffected = cmd.ExecuteNonQuery();
                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                        throw;
                    }
                    finally
                    {
                        try
                        {
                            conn.Close();
                        }
                        catch { }
                    }
                    //SqlCommand myCommand = new SqlCommand("SELECT * FROM table WHERE Column = @Param2", myConnection);
                    //myCommand.Parameters.Add(myParam2);

                    //conn.tran
                }
            }


            //conn.Open();  

            return rowsAffected;
        }
        */
    }
}